package golk

func rotate(matrix [][]int) {
	n := len(matrix)
	if n == 1 {
		return
	}
	var tmp, i, j int
	// mirror by diagonal
	for i = 0; i < n; i++ {
		for j = i; j < n; j++ {
			tmp = matrix[i][j]
			matrix[i][j] = matrix[j][i]
			matrix[j][i] = tmp
		}
	}
	// reverse the element order in each row
	for i = 0; i < n; i++ {
		for j = 0; j < n-j-1; j++ {
			tmp = matrix[i][j]
			matrix[i][j] = matrix[i][n-1-j]
			matrix[i][n-1-j] = tmp
		}
	}
}
